package com.jmc.calls;


import java.io.Serializable;
import java.sql.SQLException;
import java.sql.Timestamp;

import com.ibm.as400.access.AS400;
import com.ibm.as400.access.AS400Message;
import com.ibm.as400.access.AS400Text;
import com.ibm.as400.access.CommandCall;
import com.ibm.as400.access.ProgramCall;
import com.ibm.as400.access.ProgramParameter;

public class TestProgramCallPD0008 implements Serializable{

	public static void main(String[] args) throws SQLException{
		//System.out.println("Inicio: " + new Timestamp(System.currentTimeMillis()));
		runPG("/QSYS.LIB/TRFPGMLIB.LIB/PD0008CLWE.PGM");
		//System.out.println("Fin: " + new Timestamp(System.currentTimeMillis()));		
	}
	public static void runPG(String dir){
		// Call programs on system "Hal"
		
		AS400 as400 = new AS400("www.transfurlong.com.ar", "qsecofer", "c2259");
		System.out.println("Inicio: " + new Timestamp(System.currentTimeMillis()));
		ProgramCall pgm = new ProgramCall( as400 );
		try
		{
		//Agrego la Libreria de Datos
		CommandCall cmd = new CommandCall( as400 );
		cmd.run("CHGDTAARA  DTAARA(*LDA (519 3)) VALUE('002')");
		cmd.run("CHGDTAARA  DTAARA(*LDA (701 6)) VALUE('123456')");  

		// Show the messages (returned whether or not there was an error)
		
		AS400Message[] messagelistCommand = cmd.getMessageList();
		for (int i=0; i < messagelistCommand.length; i++)
		{
		// show each message
		System.out.println(messagelistCommand[i].getText() );
		}
		
		// Initialize the name of the program to run
		String progName = "/QSYS.LIB/TRFPGMLIB.LIB/PD0008CLWE.CLP";
		// Setup the 3 parameters
		progName = dir;
		// First parameter is to input a name
		
		pgm.setProgram( progName );
		// Run the program
		if (pgm.run()!=true)
		{
		// Note that there was an error
		System.out.println( "program failed!" );
		// Show the messages
		
		AS400Message[] messagelist = pgm.getMessageList();
		for (int i=0; i < messagelist.length; i++)
		{
		// show each message
		System.out.println( messagelist[i] );
		}
		}
		else
		{
		AS400Text text = null;
		}
		
		}
		catch (Exception e)
		{
		System.out.println( "Program " + pgm.getProgram() + " did not run!" );
		e.printStackTrace();
		}
		
		// done with the system
		//as400.disconnectAllServices();
		System.out.println("Fin: " + new Timestamp(System.currentTimeMillis()));
			
	}
}
